package a.面试;

import org.junit.Test;
import 其他.DataStructure.ListNode;



public class Main2 {

    @Test
    public void test() {
        ListNode a1=new ListNode(1);
        ListNode a2=new ListNode(2);
        ListNode a3=new ListNode(3);
        ListNode a4=new ListNode(4);
        a1.next=a2;a2.next=a3;a3.next=a4;
        ListNode newHead = fuanzhuan(a1);
        while(newHead!=null){
            System.out.print(newHead.val+" ");
            newHead=newHead.next;
        }
    }

    public ListNode fuanzhuan(ListNode head){
        ListNode fir=head; if(head==null)return null;
        ListNode sec=head.next;
        //
        while(sec!=null){
            ListNode tmp=sec.next;
            sec.next=fir;
            fir=sec;
            sec=tmp;
        }
        //
        head.next=null;
        return fir;
    }

}
